home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Panorama / Panorama - Disk 28C (1988-04-27)(Pacific North-West Amigas Club)[WB].zip / Panorama - Disk 28C (1988-04-27)(Pacific North-West Amigas Club)[WB].adf / Ifs / ifs.c < prev    next >
C/C++ Source or Header  |  1988-02-08  |  6KB  |  266 lines

  1. /************************************************************************
  2. *
  3. *  Title: ifs.c
  4. *
  5. ************************************************************************/
  6.  
  7. #include <stdio.h>
  8. #include <math.h>
  9. #include <functions.h>
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <intuition/intuition.h>
  13.  
  14. struct GfxBase *GfxBase;
  15. struct IntuitionBase *IntuitionBase;
  16. double ran();
  17.  
  18. /* */
  19. /* Short function to open up required libraries. */
  20. /* */
  21.  
  22. void Init()
  23.  
  24. {
  25.  
  26. if( !(IntuitionBase=
  27.      (struct IntuitionBase *)OpenLibrary("intuition.library",0L)) )
  28.    {
  29.    printf("Error opening intuition.library\n");
  30.    Exit(20L);
  31.    }
  32.  
  33. if( !(GfxBase=
  34.      (struct GfxBase *)OpenLibrary("graphics.library",0L)) )
  35.    {
  36.    printf("Error opening graphics.library\n");
  37.    CloseLibrary(IntuitionBase);
  38.    Exit(20L);
  39.    }
  40.  
  41. }
  42.  
  43.  
  44.  
  45. /**/
  46. /* Function which actually makes OpenWindow call. */
  47. /**/
  48.  
  49. struct Window *SetWindow(title,left,top,width,height)
  50.  
  51. short left,top,width,height;
  52. char *title;
  53.  
  54. {
  55.  
  56. struct NewWindow *nw;
  57. struct Window *wp;
  58.  
  59. nw=(struct NewWindow *)AllocMem((long)(sizeof(struct NewWindow)),MEMF_CHIP);
  60. if( !nw )
  61.    {
  62.    printf("Error allocating NewWindow structure\n");
  63.    CloseLibrary(GfxBase);
  64.    CloseLibrary(IntuitionBase);
  65.    Exit(20L);
  66.    }
  67.    
  68. nw->LeftEdge=left;
  69. nw->TopEdge=top;
  70. nw->Width=width;
  71. nw->Height=height;
  72. nw->DetailPen=0;
  73. nw->BlockPen=1;
  74. nw->IDCMPFlags=MENUPICK|CLOSEWINDOW;
  75. nw->Flags=SMART_REFRESH|ACTIVATE|WINDOWSIZING|WINDOWCLOSE|WINDOWDRAG|
  76.           WINDOWDEPTH;
  77. nw->FirstGadget=NULL;
  78. nw->CheckMark=NULL;
  79. nw->Title=(unsigned char *)title;
  80. nw->Screen=(struct Screen *)NULL;
  81. nw->BitMap=(struct BitMap *)NULL;
  82. nw->MinWidth=10;
  83. nw->MinHeight=10;
  84. nw->MaxWidth=640;
  85. nw->MaxHeight=200;
  86. nw->Type=WBENCHSCREEN;
  87.  
  88. wp=(struct Window *)OpenWindow(nw);
  89. FreeMem(nw,(long)(sizeof(struct NewWindow)));
  90. if( !wp )
  91.    {
  92.    printf("Error opening window\n");
  93.    CloseLibrary(GfxBase);
  94.    CloseLibrary(IntuitionBase);
  95.    Exit(20L);
  96.    }
  97.  
  98. return(wp);
  99.  
  100. }
  101.  
  102.  
  103.  
  104. /**/
  105. /* Function to setup menu and monitor messages for close window signal */
  106. /**/
  107.  
  108. void QuitWindow(wp)
  109.  
  110. struct Window *wp;
  111.  
  112. {
  113.  
  114. long  class,code;                     /* Event information */
  115.  
  116. struct IntuiMessage *message;         /* Gets input event */
  117.  
  118. static struct IntuiText menu_text = { /* Menu description */
  119.    2,1,JAM2,                          /* Frontpen, Backpen, Draw mode */
  120.    20,1, NULL,                        /* Left and Top offsets, Font */
  121.    (UBYTE *)"QUIT",NULL };            /* Text to display, next IntuiText */
  122.  
  123. static struct MenuItem menu_item = {
  124.    NULL, 0,0,100,10,                  /* Next item,Left,Top,Width,Height */
  125.    HIGHBOX |ITEMENABLED |MENUTOGGLE |
  126.    ITEMTEXT |CHECKIT |COMMSEQ,
  127.    NULL,(APTR)&menu_text,             /* MutualExclude, ItemFill */
  128.    NULL, 'Q', NULL };                 /* SelectFill, Command , SubItem */
  129.  
  130. static struct Menu menu = {
  131.    NULL, 0,0,60,10,                   /* Next item, Left,Top,Width,Height */
  132.    MENUENABLED, "Menu",               /* Flags , text */
  133.    &menu_item };                      /* Pointer to first menu-item */
  134.  
  135. SetMenuStrip( wp, &menu );
  136.  
  137. while(1)                      /* Infinite loop */
  138.    {
  139.    WaitPort(wp->UserPort);    /* Wait for input event */
  140.    message=(struct IntuiMessage *)GetMsg(wp->UserPort);
  141.    class=message->Class;      /* Get event info */
  142.    code=message->Code;
  143.    ReplyMsg(message);         /* Tell intuition we're through with event */
  144.    switch(class)              /* Process the input event */
  145.       {
  146.       case MENUPICK:
  147.          if ( (MENUNUM(code)==0) && (ITEMNUM(code)==0) )
  148.         goto quit;        /* I know ... 'goto' in a C program. */
  149.      break;               /* Pretty or not, it looks like the */
  150.       case CLOSEWINDOW:       /* fastest way to get out of this while */
  151.          goto quit;           /* loop. */
  152.      break;
  153.       }
  154.  
  155.    }
  156.  
  157. quit:
  158. ClearMenuStrip(wp);
  159. CloseWindow(wp);
  160. CloseLibrary(GfxBase);
  161. CloseLibrary(IntuitionBase);
  162.  
  163. }
  164.  
  165.  
  166.  
  167. /**/
  168. /* Main function */
  169. /**/
  170.  
  171. main()
  172.  
  173. {
  174.  
  175. struct Window *wp;
  176. struct RastPort *rp;
  177. float a[10],b[10],c[10],d[10],e[10],f[10],p[10];
  178. float x,y,newx,newy,xscale,yscale,xoffset,yoffset,pk,pt;
  179. long left,top,width,height;
  180. long i,j,m,px,py;
  181. unsigned long iters;
  182.  
  183. newx=newy=x=y=pt=0.;
  184.  
  185. printf("IFS Input Data\n");
  186.  
  187. Init();
  188. if(4!=scanf("%ld%ld%ld%ld",&left,&top,&width,&height))
  189.    {
  190.    printf("Error Reading Window Specifications -> left top width height\n");
  191.    goto quit;
  192.    }
  193. printf("Window Specifications -> %ld %ld %ld %ld\n",left,top,width,height);
  194. wp=SetWindow("SimpleWindow",left,top,width,height);
  195. rp=wp->RPort;
  196.  
  197. if(1!=scanf("%ld",&iters))
  198.    {
  199.    printf("Error Reading Number of Iterations -> iters\n");
  200.    goto quit;
  201.    }
  202. if(iters>4294967295)
  203.    {
  204.    printf("Too Many Iterations, Maximum -> 4,294,967,295\n");
  205.    goto quit;
  206.    }
  207.  
  208. printf("Number of Iterations -> %ld\n",iters);
  209.  
  210. if(4!=scanf("%f%f%f%f",&xoffset,&yoffset,&xscale,&yscale))
  211.    {
  212.    printf("Error Reading Offsets or Scales -> xoffset yoffset xscale yscale\n");
  213.    goto quit;
  214.    }
  215.  
  216. printf("Offsets and Scaling -> %f %f %f %f\n",xoffset,yoffset,xscale,yscale);
  217.  
  218. if(1!=scanf("%ld",&m))
  219.    {
  220.    printf("Error Reading Number of Transformations -> m\n");
  221.    goto quit;
  222.    }
  223.  
  224. printf("Number of Transformations -> %ld\n",m);
  225.  
  226. for(i=0L;i<m;i++)
  227.    {
  228.    if(7!=scanf("%f%f%f%f%f%f%f",&a[i],&b[i],&c[i],&d[i],&e[i],&f[i],&pk))
  229.       {
  230.       printf("Error Reading Transformation Coefficients -> a. b. c. d. e. f. p.\n");
  231.       goto quit;
  232.       }
  233.    printf("Coefficients -> %f %f %f %f %f %f %f\n",a[i],b[i],c[i],d[i],e[i],f[i],pk);
  234.    pt=pt+pk;
  235.    p[i]=pt;
  236.    }
  237.  
  238. for(i=0L;i<10L;i++)
  239.    {
  240.    pk=(float)ran();
  241.    for(j=0L;p[j]<pk && j<m;j++);
  242.    newx=a[j]*x+b[j]*y+e[j];
  243.    newy=c[j]*x+d[j]*y+f[j];
  244.    x=newx;
  245.    y=newy;
  246.    }
  247.    
  248. for(i=0L;i<iters;i++)
  249.    {
  250.    pk=(float)(ran());
  251.    for(j=0L;p[j]<pk && j<m;j++);
  252.    newx=a[j]*x+b[j]*y+e[j];
  253.    newy=c[j]*x+d[j]*y+f[j];
  254.    x=newx;
  255.    y=newy;
  256.    px=(long)(x*xscale+xoffset);
  257.    py=(long)(height-(y*yscale+yoffset));
  258.    if(px>0L && px<width && py>0L && py<height)
  259.       WritePixel(rp,px,py);
  260.    }
  261.  
  262. quit:
  263. QuitWindow(wp);
  264.  
  265. }
  266.